package com.example.rg1activitygameapp;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.google.gson.Gson;

public class ShopActivity extends AppCompatActivity {

    private Button button1;
    private Button button2;
    private Button button3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shop);

        button1=findViewById(R.id.button1);
        button2=findViewById(R.id.button2);
        button3=findViewById(R.id.button3);

        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Weapon sword=new Weapon(300,50,100);
                setWeaponResult(sword);
            }
        });

        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Weapon shield=new Weapon(50,300,100);
                setWeaponResult(shield);
            }
        });

        button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Weapon weapon=new Weapon(300,300,50);
                setWeaponResult(weapon);
            }
        });
    }

    private void setWeaponResult(Weapon weapon)
    {
        Intent intent=new Intent();
        Gson gson=new Gson();
        String weaponStr=gson.toJson(weapon);

        intent.putExtra("weapon",weaponStr);
        setResult(RESULT_OK,intent);
        finish();
    }
}
